package com.xiaoshangkou.smalltv2.ui.slideshow;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;

import com.xiaoshangkou.smalltv2.databinding.FragmentSlideshowBinding;

public class SlideshowFragment extends Fragment {

    private SlideshowViewModel slideshowViewModel;
    private FragmentSlideshowBinding binding;

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        slideshowViewModel =
                new ViewModelProvider(this).get(SlideshowViewModel.class);

        binding = FragmentSlideshowBinding.inflate(inflater, container, false);
        View root = binding.getRoot();

//        final TextView textView = binding.textSlideshow;
        //获取列表视图的对象
        ListView listView =binding.listview;

        String[] strings=new String[]{
                "关于作者","软件声明"
        };
        //适配器
        ArrayAdapter<String> arrayAdapter=new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1,strings);
        listView.setAdapter(arrayAdapter);
        //为列表视图绑定监听事件
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                //Toast.makeText(getActivity(), strings[i], Toast.LENGTH_SHORT).show();
                //如果用户点击了关于作者下面同理
                if ("关于作者".equals(strings[i])){
                    Intent intent1=new Intent(getActivity(), aboutAuther.class);
//                    启动Activity
                    startActivity(intent1);


                }
                else if ("软件声明".equals(strings[i])){
                    Intent intent2=new Intent(getActivity(), Statement.class);
//                    启动Activity
                    startActivity(intent2);

                }

            }
        });
        return root;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }
}